/**
 * 
 */
app.config(function($stateProvider) {
	$stateProvider.state('recrut2', {
		url: '/recrut2',
		templateUrl: './views/re-recrut2.html',
		controller: ['$state', function($state) {
			$state.go('recrut2.dmdreq')
		}]
	}).state('recrut3',{
		url: '/recrut3',
		templateUrl: './views/re-recrut3.html',
		controller: ['$state', function($state) {
			$state.go('recrut3.dmdpri')
		}]
	});
});
var OnBoarding=[];
var addDrmsRequestID=[];
var addDrmsCandID=[];
var editDrmsRequestID=[];
var editDrmsCandID=[];
app.config(function($stateProvider) {
	$stateProvider.state('recrut2.onbor', {
		url: '/onbor',
		templateUrl: './views/Onboarding.html',
		controller: [ '$state', function( $state) {
			var state = $state;
			jQuery(function($) {
				var currentPage;
				var id;
				var baseUrl;
				function findPageDeatil(data){
					console.log(data);
					$.ajax({
						url:baseUrl,
						type : "POST",
						data:data,
						contentType : "application/json",
						async : true,
						success : function(data) {
							$('.tdb').empty();
							$('.tdb').append(
									'<tr style="color:#FFF;background-color:#A8B8C2;font-size: 13px; border:1px solid" id="thr">'+
									 '<th class="th" scope="col" width="9%" colspan="2" id="CGID">CG ID</th>'+
						             '<th class="th" scope="col" width="10%" colspan="2" id="AccountID">Account</th>'+
						             '<th class="th" scope="col" width="10%" colspan="2" id="CapabilityID">Capability</th>'+
						             '<th class="th" scope="col" width="15%" colspan="2" id="DemandRequestID">DemandRequest</th>'+
						             '<th class="th" scope="col" width="8%" colspan="2" id="CandidateID">Candidate</th>'+
					            	 '<th class="th" scope="col" width="8%" colspan="2" id="EnglishName">EnglishName</th>'+
					            	 '<th class="th" scope="col" width="9%" colspan="2" id="ChineseName">ChineseName</th>'+
						             '<th class="th" scope="col" width="8%" colspan="2" id="JoinDate">JoinDate</th>'+
		   				             '<th class="th" scope="col" width="8%" colspan="2" id="Status">Status</th>'+
						             '<th class="th" scope="col" width="10%" colspan="2" id="Language">Language</th>'+
						             '<th class="th" scope="col" width="5%" colspan="2" id="Option">Option</th>'+
						             '</tr>');
				if(data!=null ||data!=0){
					var list=data.list;	
					console.log(data.pageNo);
					console.log(data.totalPageNo);
					console.log(list);
					OnBoarding=data.list;
					for(var i=0;i<OnBoarding.length;i++){
						var accountName="";
						if(OnBoarding[i].drmsAccount!=null){
						accountName=OnBoarding[i].drmsAccount.accountName;
						}
						var capName="";
						if(OnBoarding[i].drmsCapability!=null){
						capName=OnBoarding[i].drmsCapability.capName;
						}
						var demandShowId="";
						if(OnBoarding[i].drmsDemandRequest!=null){
						demandShowId=OnBoarding[i].drmsDemandRequest.demandShowId;
						}
						var candShowId="";
						if(OnBoarding[i].drmsCandidate!=null){
						candShowId=OnBoarding[i].drmsCandidate.candShowId;
						}
						var cgId="";
						if(OnBoarding[i].cgId!=null || OnBoarding[i].cgId!=""){
							cgId=OnBoarding[i].cgId;
						}
						var englishName="";
						if(OnBoarding[i].englishName!=null || OnBoarding[i].englishName!=""){
							englishName=OnBoarding[i].englishName;
						}
						var chineseName="";
						if(OnBoarding[i].chineseName!=null || OnBoarding[i].chineseName!=""){
							chineseName=OnBoarding[i].chineseName;
						}
						var joinDate="";
						console.log(format(OnBoarding[i].joinDate)!=format(new Date((new Date("1970-01-01")))))
						if(format(OnBoarding[i].joinDate)!=format(new Date((new Date("1970-01-01"))))){
							joinDate=format(OnBoarding[i].joinDate);
						}
						var status="";
						if(OnBoarding[i].status!=null || OnBoarding[i].status!=""){
							status=OnBoarding[i].status;
						}
						var language="";
						if(OnBoarding[i].language!=null || OnBoarding[i].language!=""){
							language=OnBoarding[i].language;
						}
							$('.tdb').append(
									 '<tr align="center" style="background-color:white;border:1px solid #ddd">'+
									 '<td class="th" scope="col" width="9%" colspan="2">'+cgId+ '</td>'+
									 '<td class="th" scope="col" width="10%" colspan="2">'+accountName+ '</td>'+
									 '<td class="th" scope="col" width="10%" colspan="2">'+capName+ '</td>'+
									 '<td class="th" scope="col" width="15%" colspan="2">'+demandShowId+ '</td>'+
									 '<td class="th" scope="col" width="8%" colspan="2">'+candShowId+ '</td>'+
									 '<td class="th" scope="col" width="8%" colspan="2">'+englishName+ '</td>'+
									 '<td class="th" scope="col" width="9%" colspan="2">'+chineseName+ '</td>'+
									 '<td class="th" scope="col" width="8%" colspan="2">'+joinDate+ '</td>'+
									 '<td class="th" scope="col" width="8%" colspan="2">'+status+ '</td>'+
									 '<td class="th" scope="col" width="10%" colspan="2">'+language+ '</td>'+
									 '<td class="th" scope="col" width="5%" colspan="2"><span  id="'+i+'" class="tb-edit"></span></td>'+
									 '</tr>');
							        }   
								currentPage=data.pageNo;
								document.cookie="currentPage="+currentPage;
								$('.totalPageNo').html(data.totalPageNo);
								$('.currentPageNo').html(currentPage)
								$('.pageNumber').empty();
								var totalPage=data.totalPageNo;
								if(totalPage<=5){
										for(var i=1;i<=totalPage;i++){
											if(i==currentPage){
												$('.pageNumber').append("<input type='button' class='paging click' style='background-color:#fff;border:1px solid #ddd;padding-top:5px;padding-right:10px;padding-bottom:5px;padding-left:10px;text-align:center;' value='"+i+"'>");
											}else{
												$('.pageNumber').append("<input type='button' class='paging' style='background-color:#fff;border:1px solid #ddd;padding-top:5px;padding-right:10px;padding-bottom:5px;padding-left:10px;text-align:center;' value='"+i+"'>");
											}
										}
									}else{
										if(currentPage<=3){
											for(var i=1;i<=5;i++){
												if(i==currentPage){
													$('.pageNumber').append("<input type='button' class='paging click' style='background-color:#fff;border:1px solid #ddd;padding-top:5px;padding-right:10px;padding-bottom:5px;padding-left:10px;text-align:center;' value='"+i+"'>");
												}else{
													$('.pageNumber').append("<input type='button' class='paging' style='background-color:#fff;border:1px solid #ddd;padding-top:5px;padding-right:10px;padding-bottom:5px;padding-left:10px;text-align:center;' value='"+i+"'>");
												}
											}
										}else{
											if(currentPage>totalPage-4){
												for(var i=totalPage-4;i<=totalPage;i++){
													if(i==currentPage){
														$('.pageNumber').append("<input type='button' class='paging click' style='background-color:#fff;border:1px solid #ddd;padding-top:5px;padding-right:10px;padding-bottom:5px;padding-left:10px;text-align:center;' value='"+i+"'>");
													}else{
														$('.pageNumber').append("<input type='button' class='paging' style='background-color:#fff;border:1px solid #ddd;padding-top:5px;padding-right:10px;padding-bottom:5px;padding-left:10px;text-align:center;' value='"+i+"'>");
													}
												}
											}else{
												for(var i=currentPage-2;i<currentPage+3;i++){
													if(i==currentPage){
														$('.pageNumber').append("<input type='button' class='paging click' style='background-color:#fff;border:1px solid #ddd;padding-top:5px;padding-right:10px;padding-bottom:5px;padding-left:10px;text-align:center;' value='"+i+"'>");
													}else{
														$('.pageNumber').append("<input type='button' class='paging' style='background-color:#fff;border:1px solid #ddd;padding-top:5px;padding-right:10px;padding-bottom:5px;padding-left:10px;text-align:center;' value='"+i+"'>");
													}
												}
											}
										}
									}
							}
						}
					})
				}
				
				$(document).ready(function(){
					
					$('body').on('click', '.paging', function(event) {
						findPage(this);
					});
					$('body').on('click', '#prev', function(event) {
						prevPage(this);
					});
                    $('body').on('click', '#next', function(event) {
                    	nextPage(this);	
					});
                    $('body').on('click', '.tb-edit', function(event) {
                    	state.go('recrut2.onbor.edit');
                    	var i=$(this).attr('id');
                    	console.log(i);
                    	console.log(OnBoarding[i]);
                    	id=OnBoarding[i].id;
                    	document.cookie="id="+id;
                    	findOnboardingById(id);             	
                    	console.log($(this).attr('id'));
                    	console.log($('.tb-edit'));
                    	event.preventDefault();
					});     
					var string = null;
					baseUrl="./api/DrmsOnboarding/findDrmsOnboarding";
					var page1={
							pageNo:"",
							pageRecordSize:"",
							list:null,
							totalPageNo:"",
							parameter:string
						}
					var data=JSON.stringify(page1);
					findPageDeatil(data);
					})
					
				function findPage(obj){
					baseUrl="./api/DrmsOnboarding/findDrmsOnboarding";
					var string = document.getElementById("name").value;
					console.log(string);
					var i=obj.value;
					var page2={
							pageNo:i,
							pageRecordSize:"",
							list:null,
							totalPageNo:"",
							parameter:string
						}
					console.log(obj);
					var data=JSON.stringify(page2);
					findPageDeatil(data);
				}

				function prevPage(obj){
					baseUrl="./api/DrmsOnboarding/findDrmsOnboarding";
					var string = document.getElementById("name").value;
					console.log(string);
					var w=get_cookie("currentPage");
					console.log(w);
					var prevPage=w-1;
					console.log(prevPage);
					var page2={
							pageNo:prevPage,
							pageRecordSize:"",
							list:null,
							totalPageNo:"",
							parameter:string
						}
					console.log(obj);
					var data=JSON.stringify(page2);
					findPageDeatil(data);
				}
				
				$('#name').keyup(function(){
					var string = document.getElementById("name").value;
					baseUrl="./api/DrmsOnboarding/findDrmsOnboarding";
					var page2={
							pageNo:"",
							pageRecordSize:"",
							list:null,
							totalPageNo:"",
							parameter:string
						}
					var regex=/\w{3} \d{2}, \d{4}/;
					console.log(page2.parameter.match(regex));
					if(page2.parameter.match(regex)){
						
						var a=new Date(page2.parameter);
						var b=a.getFullYear()+"-"+add0((a.getMonth()+1))+"-"+a.getDate();
						console.log(b);
						page2.parameter=b;
						var data=JSON.stringify(page2);
						findPageDeatil(data);
					}else{
						var data=JSON.stringify(page2);
						findPageDeatil(data);
					}
					})
				
				function nextPage(obj){
					baseUrl="./api/DrmsOnboarding/findDrmsOnboarding";
					var string = document.getElementById("name").value;
					console.log(string);
					var w=get_cookie("currentPage");
					console.log(w);
					var nextPage=w*1+1;
					var page2={
							pageNo:nextPage,
							pageRecordSize:"",
							list:null,
							totalPageNo:"",
							parameter:string
						}
					console.log(obj);
					var data=JSON.stringify(page2);
					findPageDeatil(data);
				}
			});	
		}]
	}).state('recrut2.onbor.add', {
		url: '/add',
		templateUrl: './views/onborSlide.html',
		controller:  ['$state', function($state) {
			jQuery(function($) {
				$('#slidelst').on('click',function(){
					$('#ADR').hide();
					$('#ADC').hide();
				})
				$('#add_join_date').datetimepicker({
					lang:'ch',
					timepicker:false,
					format:'M d, Y',
					formatDate:'M/d/Y',
					scrollInput:false
				});
				boxStyleChange();
				$('#add_demand_request').keyup(function(){
					var DRID=document.getElementById("add_demand_request").value;
					$.ajax({
						url:"./api/DrmsOnboarding/findDemandRequestByDemandShowId?DDRID="+DRID,
						type : "POST",
						async : true,
						contentType : "application/json",
						success:function(data) {
							addDrmsRequestID=data;
							if(data!=null && data!=""){
								$('#ADRData').empty();
								$('#ADR').show();
								for(var i=0;i<data.length;i++){
									$('#ADRData').append('<li id="'+data[i]+'" onclick="giveValue(this);"onmouseover="changeColor(this)"onmouseout="backColor(this)"style="display：block;padding-left:5px;">'+data[i]+'</li>');
									}
							}else{
								$('#ADR').hide();
							}
						}
				})
			})
			$('#add_demand_request').on('click',function(event){
				event.stopPropagation();
				if($('#add_demand_request').val()!=""){
					var DRID=$('#add_demand_request').val();
					$.ajax({
						url:"./api/DrmsOnboarding/findDemandRequestByDemandShowId?DDRID="+DRID,
						type : "POST",
						async : true,
						contentType : "application/json",
						success:function(data) {
							addDrmsRequestID=data;
							if(data!=null && data!=""){
								$('#ADR').show();
								$('#ADRData').empty();
								for(var i=0;i<data.length;i++){
									$('#ADRData').append('<li id="'+data[i]+'" onclick="giveValue(this);"onmouseover="changeColor(this)"onmouseout="backColor(this)"style="display：block;padding-left:5px;">'+data[i]+'</li>');
									}
							}else{
								$('#ADR').hide();
							}
						}
				})
				}
			})
			$('#add_candidate').keyup(function(){
				var DCID=document.getElementById("add_candidate").value;
				$.ajax({
					url:"./api/DrmsOnboarding/findCandidateByCandShowId?DCID="+DCID,
					type : "POST",
					async : true,
					contentType : "application/json",
					success:function(data) {
						addDrmsCandID=data;
						if(data!=null && data!=""){
							$('#ADCData').empty();
							$('#ADC').show();
							for(var i=0;i<data.length;i++){
								$('#ADCData').append('<li id="'+data[i]+'" onclick="giveCandValue(this);"onmouseover="changeColor(this)"onmouseout="backColor(this)"style="display：block;padding-left:5px;">'+data[i]+'</li>');
								}
						}else{
							$('#ADC').hide();
						}
					}
			})
		})
			$('#add_candidate').on('click',function(event){
				event.stopPropagation();
				if($('#add_candidate').val()!=""){
					var DCID=$('#add_candidate').val();
					$.ajax({
						url:"./api/DrmsOnboarding/findCandidateByCandShowId?DCID="+DCID,
						type : "POST",
						async : true,
						contentType : "application/json",
						success:function(data) {
							addDrmsCandID=data;
							if(data!=null && data!=""){
								$('#ADCData').empty();
								$('#ADC').show();
								for(var i=0;i<data.length;i++){
									$('#ADCData').append('<li id="'+data[i]+'" onclick="giveCandValue(this);"onmouseover="changeColor(this)"onmouseout="backColor(this)"style="display：block;padding-left:5px;">'+data[i]+'</li>');
									}
							}else{
								$('#ADC').hide();
							}
							
						}
				})
				}
			})
		
			
			
			
			})
		}]

	}).state('recrut2.onbor.edit', {
		url: '/edit',
		templateUrl: './views/onborEditSlide.html',
		controller:  ['$state', function($state) {
			jQuery(function($) {
				$('#slidelst').on('click',function(){
					$('#DR').hide();
					$('#DC').hide();
					
				})
				$('#edit_join_date').datetimepicker({
					lang:'ch',
					timepicker:false,
					format:'M d, Y',
					formatDate:'M/d/Y',
					scrollInput:false
				});
				boxStyleChange();
				$('#edit_demand_request').keyup(function(){
					var DRID=document.getElementById("edit_demand_request").value;
					$.ajax({
						url:"./api/DrmsOnboarding/findDemandRequestByDemandShowId?DDRID="+DRID,
						type : "POST",
						async : true,
						contentType : "application/json",
						success:function(data) {
							editDrmsRequestID=data;
							if(data!=null && data!=""){
								$('#DRData').empty();
								$('#DR').show();
								for(var i=0;i<data.length;i++){
									$('#DRData').append('<li id="'+data[i]+'" onclick="giveValue(this);"onmouseover="changeColor(this)"onmouseout="backColor(this)"style="display：block;padding-left:5px;">'+data[i]+'</li>');
									}
							}else{
								$('#DR').hide();
							}
						}
				})
			})
			$('#edit_demand_request').on('click',function(event){
				event.stopPropagation();
				if($('#edit_demand_request').val()==""){
					$('#DR').hide();
				}
				var DRID=$('#edit_demand_request').val();
				$.ajax({
					url:"./api/DrmsOnboarding/findDemandRequestByDemandShowId?DDRID="+DRID,
					type : "POST",
					async : true,
					contentType : "application/json",
					success:function(data) {
						editDrmsRequestID=data;
						if(data!=null && data!=""){
							$('#DRData').empty();
							$('#DR').show();
							for(var i=0;i<data.length;i++){
								$('#DRData').append('<li id="'+data[i]+'" onclick="giveValue(this);"onmouseover="changeColor(this)"onmouseout="backColor(this)"style="display：block;padding-left:5px;">'+data[i]+'</li>');
								}
						}else{
							$('#DR').hide();
						}
					}
			})
			})
			
			
			$('#edit_candidate').keyup(function(){
				var DCID=document.getElementById("edit_candidate").value;
				$.ajax({
					url:"./api/DrmsOnboarding/findCandidateByCandShowId?DCID="+DCID,
					type : "POST",
					async : true,
					contentType : "application/json",
					success:function(data) {
						editDrmsCandID=data;
						if(data!=null && data!=""){
							$('#DCData').empty();
							$('#DC').show();
							for(var i=0;i<data.length;i++){
								$('#DCData').append('<li id="'+data[i]+'" onclick="giveCandValue(this);"onmouseover="changeColor(this)"onmouseout="backColor(this)" style="display：block;padding-left:5px;">'+data[i]+'</li>');
								}
						}else{
							$('#DC').hide();
						}
					}
			})
		})
			$('#edit_candidate').on('click',function(event){
				event.stopPropagation();
				if($('#edit_candidate').val()==""){
					$('#DC').hide();
				}
				var DCID=document.getElementById("edit_candidate").value;
				console.log(DCID);
				$.ajax({
					url:"./api/DrmsOnboarding/findCandidateByCandShowId?DCID="+DCID,
					type : "POST",
					async : true,
					contentType : "application/json",
					success:function(data) {
						editDrmsCandID=data;
						if(data!=null && data!=""){
							$('#DCData').empty();
							$('#DC').show();
							for(var i=0;i<data.length;i++){
								$('#DCData').append('<li id="'+data[i]+'" onclick="giveCandValue(this);"onmouseover="changeColor(this)"onmouseout="backColor(this)" style="display：block;padding-left:5px;">'+data[i]+'</li>');
								}
						}else{
							$('#DC').hide();
						}
					}
			})
			})
			
			
			
			})
		}]

	})
})
function findOnboardingById(id){
	$.ajax({
		url:"./api/DrmsOnboarding/findOnboardingsById?id="+id,
		type : "POST",
		async : true,
		contentType : "application/json",
		success:function(data) {
			var dsgNameList=data.DsgName;
			var capNameList=data.CapName;
			var candShowIdList=data.CandShowId;
			var demandShowIdList=data.DemandShowId;
			var accountNameList=data.AccountName;
			$('#edit_cg_id').val(data.drmsOnboarding[0].cgId);
			if(data.drmsOnboarding[0].drmsDesigation!=null){
				$('#edit_cg_id').empty();
				$('#edit_cg_id').append('<option></option>');
			for(var i=0;i<dsgNameList.length;i++){
					if(data.drmsOnboarding[0].drmsDesigation.dsgName==dsgNameList[i]){
						$('#edit_designation').append(
								'<option selected="selected">'+dsgNameList[i]+'</option>'
						);
						dsgNameList.splice(i,1);
						for(var j=0;j<dsgNameList.length;j++){
							$('#edit_designation').append(
									'<option>'+dsgNameList[j]+'</option>'
							);
						}
						}
					}
				}else{
					for(var j=0;j<dsgNameList.length;j++){
						$('#edit_designation').append(
								'<option>'+dsgNameList[j]+'</option>'
						);
					}
				}
			if(data.drmsOnboarding[0].drmsCapability!=null){
				$('#edit_capability').empty();
				$('#edit_capability').append('<option></option>');
			for(var i=0;i<capNameList.length;i++){
				if(data.drmsOnboarding[0].drmsCapability.capName==capNameList[i]){
				$('#edit_capability').append(
						'<option selected="selected">'+capNameList[i]+'</option>'
				);
				capNameList.splice(i,1);
				for(var j=0;j<capNameList.length;j++){
					$('#edit_capability').append(
							'<option>'+capNameList[j]+'</option>'
					);
					
				}
				}
			}
			}else{
				for(var j=0;j<capNameList.length;j++){
					$('#edit_capability').append(
							'<option >'+capNameList[j]+'</option>'
					);
				}
			}
			if(data.drmsOnboarding[0].drmsCandidate!=null){
				$('#edit_candidate').empty();
				$('#DCData').empty();
			for(var i=0;i<candShowIdList.length;i++){
				if(data.drmsOnboarding[0].drmsCandidate.candShowId==candShowIdList[i]){
					$('#edit_candidate').val(candShowIdList[i]);
					$('#DCData').append('<li id="'+candShowIdList[i]+'" onclick="giveCandValue(this);"onmouseover="changeColor(this)"onmouseout="backColor(this)"style="display：block;padding-left:5px;">'+candShowIdList[i]+'</li>');
				}
			}
			}
			if(data.drmsOnboarding[0].drmsDemandRequest!=null){
				$('#edit_demand_request').empty();
				$('#DRData').empty();
			for(var i=0;i<demandShowIdList.length;i++){
				if(data.drmsOnboarding[0].drmsDemandRequest.demandShowId==demandShowIdList[i]){
					$('#edit_demand_request').val(demandShowIdList[i]);
					$('#DRData').append('<li id="'+data[i]+'" onclick="giveValue(this);"onmouseover="changeColor(this)"onmouseout="backColor(this)"style="display：block;padding-left:5px;">'+data[i]+'</li>');
				}
			}
			}
			if(data.drmsOnboarding[0].drmsAccount!=null){
				$('#edit_account').empty();
				$('#edit_account').append('<option></option>');
			for(var i=0;i<accountNameList.length;i++){
					if(data.drmsOnboarding[0].drmsAccount.accountName==accountNameList[i]){
						$('#edit_account').append(
								'<option selected="selected" >'+accountNameList[i]+'</option>'
						);
						accountNameList.splice(i,1);
						for(var j=0;j<accountNameList.length;j++){
							$('#edit_account').append(
									'<option>'+accountNameList[j]+'</option>'
							);
						}
					}
			}
				}else{
					for(var j=0;j<accountNameList.length;j++){
						$('#edit_account').append(
								'<option>'+accountNameList[j]+'</option>'
						);
					}
				}
			$('#edit_english_name').val(data.drmsOnboarding[0].englishName);
			$('#edit_chinese_name').val(data.drmsOnboarding[0].chineseName);
			var a=["Joined","Drop","Reject Offer","To Be Joined","To Be Offer","","Offer Negotiation","Offer Proposed","Offer Process","Offer Accepted","Hired","Onboarding Process","Hired","On Hold","Not Selected","Rejected"];
			$('#edit_status').empty();
			if(data.drmsOnboarding[0].status!=''&&data.drmsOnboarding[0].status!=null){
				for(var i=0;i<a.length;i++){
					if(data.drmsOnboarding[0].status==a[i]){
						$('#edit_status').append(
								'<option selected="selected">'+a[i]+'</option>'
						);
						a.splice(i,1);
						for(var j=0;j<a.length;j++){
							console.log(a);
							$('#edit_status').append(
							'<option>'+a[j]+'</option>'
							);
						}
					}
				}
			}else{
				$('#edit_status').append('<option></option>');
				for(var i=0;i<a.length;i++){
					$('#edit_status').append(
							'<option>'+a[i]+'</option>'
					);
				}
			}
			
			$('#edit_project').val(data.drmsOnboarding[0].project);
			$('#edit_role_name').val(data.drmsOnboarding[0].roleName);
			$('#edit_language').val(data.drmsOnboarding[0].language);
			if(format(data.drmsOnboarding[0].joinDate)!=format(new Date((new Date("1970-01-01"))))){
				$('#edit_join_date').val(format(data.drmsOnboarding[0].joinDate));
			}else{
				$('#edit_join_date').val(format(new Date()));
			}
			$('#edit_capability_supervisor').val(data.drmsOnboarding[0].capabilitySupervisor);
			$('#edit_project_leader').val(data.drmsOnboarding[0].projectLeader);
			
			var b=["N","N/A","Y"];
			$('#edit_billable_status').empty();
			$('#edit_billable_status').append('<option></option>');
			if(data.drmsOnboarding[0].billableStatus!=''&&data.drmsOnboarding[0].billableStatus!=null){
				for(var i=0;i<b.length;i++){
					if(data.drmsOnboarding[0].billableStatus==b[i]){
						$('#edit_billable_status').append(
								'<option selected="selected">'+b[i]+'</option>'
						);
						b.splice(i,1);
						for(var j=0;j<b.length;j++){
							$('#edit_billable_status').append(
							'<option>'+b[j]+'</option>'
							);
						}
					}
				}
			}else{
				for(var i=0;i<b.length;i++){
					$('#edit_billable_status').append(
							'<option>'+b[i]+'</option>'
					);
				}
			}
		}
	})
}

function deleteOnboardings(obj){
		var id=get_cookie("id");
		var d={
				id:id, 
				cgId:"",
				 englishName:"",
				 chineseName:"",
				 joinDate:"",
				 project:"",
				 projectLeader:"",
				 billableStatus:"",
				 language:"",
				 status:"",
				 roleName:"",
				 capabilitySupervisor:"",
				 drmsDesigation:{},
				 drmsCapability:{},
				drmsAccount:{},
				drmsDemandRequest:{},
				 drmsCandidate:{}
		}
		var data=JSON.stringify(d);
		var i=get_cookie("currentPage");
		var string=null;
		$.ajax({
			url:"./api/DrmsOnboarding/deleteDrmsOnboardings",
			type : "POST",
			data:data,
			async : true,
			contentType : "application/json",
			success:function() {
				if(i!=1){
					console.log(get_cookie("currentPage"));
					findPage();
				}else{
					var page1={
							pageNo:"",
							pageRecordSize:"",
							list:null,
							totalPageNo:"",
							parameter:string
						}
					var data=JSON.stringify(page1);
					loadPage(data);
				}
			}
		})
	}
function updateOnboardings(obj){
	console.log(document.cookie);
	console.log(document.cookie.length);
	console.log(get_cookie("id"));
	var id=get_cookie("id");
	var cgid=$('#edit_cg_id').val();
	var account=$('#edit_account').val();
	var capability=$('#edit_capability').val();
	var demandRequest=$('#edit_demand_request').val();
	var candidate=$('#edit_candidate').val();
	var englishName=$('#edit_english_name').val();
	var chineseName=$('#edit_chinese_name').val();
	var status=$('#edit_status').val();
	var project=$('#edit_project').val();
	var roleName=$('#edit_role_name').val();
	var language=$('#edit_language').val();
	var a=$('#edit_join_date').val();
	if(a==''){
		var b=new Date();
		var joinDate=b.getFullYear()+"-"+add0(b.getMonth()+1)+"-"+add0(b.getDate());
	}else{
		var b= new Date(a);
		var joinDate=b.getFullYear()+"-"+add0(b.getMonth()+1)+"-"+add0(b.getDate());
	}
	console.log(joinDate);
	var capabilitySupervisor=$('#edit_capability_supervisor').val();
	var projectLeader=$('#edit_project_leader').val();
	var billableStatus=$('#edit_billable_status').val();
	var designation=$('#edit_designation').val();
	console.log(id);
	var d={
			 id:id,
			 cgId:cgid,
			 englishName:englishName,
			 chineseName:chineseName,
			 joinDate:joinDate,
			 project:project,
			 projectLeader:projectLeader,
			 billableStatus:billableStatus,
			 language:language,
			 status:status,
			 roleName:roleName,
			 capabilitySupervisor:capabilitySupervisor,
			 drmsDesigation:{
			 	 dsgId:"",
			     dsgName:designation
			 },
			 drmsCapability:{
			 	 capId:"",
			     capName:capability,
			     capManager:"",
			     capShortName:""
			 },
			drmsAccount:{
			     accountId:"",
		         accountName:account,
		         shortName:"",
		         accountPartner:""
			 },
			drmsDemandRequest:{
			     id:"",
			     raiseDate:"",
			     isflp:"",
			     hiringReason:"",
			     refName:"",
			     language:"",
			     primarySkill:"",
			     secondarySkill:"",
			     targetJoinDate:"",
			     status:"",
			     demandShowId:demandRequest
			 },
			 drmsCandidate:{
			     candId:"",
			     candShowId:candidate,
			     candName:"",
			     recruiter:"",
			     resource:"",
			     resume:"",
			     contactDate:"",
			     currentLocation:"",
			     telphone:"",
			     email:"",
			     year:"",
			     currentCompany:"",
			     currentSalary:"",
			     dep:"",
			     position:"",
			     status:"",
			     comments:"",
			     domain:"",
			     skills:"",
			     language:""
			 }
	}
	console.log(d);
	var data=JSON.stringify(d);
	var i=get_cookie("currentPage");
	var string=null;
	$.ajax({
		url:"./api/DrmsOnboarding/updateDrmsOnboardings",
		type : "POST",
		data:data,
		contentType : "application/json",
		async : true,
		success:function() {
			if(i!=1){
				console.log(get_cookie("currentPage"));
				findPage();
			}else{
				var page1={
						pageNo:"",
						pageRecordSize:"",
						list:null,
						totalPageNo:"",
						parameter:string
					}
				var data=JSON.stringify(page1);
				loadPage(data);
			}
		}
	})
	}
         function addOnboardings(obj){
        	 var cgid=$('#add_cg_id').val();
        		var account=$('#add_account').val();
        		var capability=$('#add_capability').val();
        		var demandRequest=$('#add_demand_request').val();
        		var candidate=$('#add_candidate').val();
        		var englishName=$('#add_english_name').val();
        		var chineseName=$('#add_chinese_name').val();
        		var status=$('#add_status').val();
        		var project=$('#add_project').val();
        		var roleName=$('#add_role_name').val();
        		var language=$('#add_language').val();
        		var a=$('#add_join_date').val();
        		if(a==''){
        			var b=new Date();
        			var joinDate=b.getFullYear()+"-"+add0(b.getMonth()+1)+"-"+add0(b.getDate());
        		}else{
        			var b= new Date(a);
            		var joinDate=b.getFullYear()+"-"+add0(b.getMonth()+1)+"-"+add0(b.getDate());
        		}
        		console.log(joinDate);
        		var capabilitySupervisor=$('#add_capability_supervisor').val();
        		var projectLeader=$('#add_project_leader').val();
        		var billableStatus=$('#add_billable_status').val();
        		var designation=$('#add_designation').val();
        		var d={
        				 cgId:cgid,
        				 englishName:englishName,
        				 chineseName:chineseName,
        				 joinDate:joinDate,
        				 project:project,
        				 projectLeader:projectLeader,
        				 billableStatus:billableStatus,
        				 language:language,
        				 status:status,
        				 roleName:roleName,
        				 capabilitySupervisor:capabilitySupervisor,
        				 drmsDesigation:{
        				 	 dsgId:"",
        				     dsgName:designation
        				 },
        				 drmsCapability:{
        				 	 capId:"",
        				     capName:capability,
        				     capManager:"",
        				     capShortName:""
        				 },
        				drmsAccount:{
        				     accountId:"",
        			         accountName:account,
        			         shortName:"",
        			         accountPartner:""
        				 },
        				drmsDemandRequest:{
        				     id:"",
        				     raiseDate:"",
        				     isflp:"",
        				     hiringReason:"",
        				     refName:"",
        				     language:"",
        				     primarySkill:"",
        				     secondarySkill:"",
        				     targetJoinDate:"",
        				     status:"",
        				     demandShowId:demandRequest
        				 },
        				 drmsCandidate:{
        				     candId:"",
        				     candShowId:candidate,
        				     candName:"",
        				     recruiter:"",
        				     resource:"",
        				     resume:"",
        				     contactDate:"",
        				     currentLocation:"",
        				     telphone:"",
        				     email:"",
        				     year:"",
        				     currentCompany:"",
        				     currentSalary:"",
        				     dep:"",
        				     position:"",
        				     status:"",
        				     comments:"",
        				     domain:"",
        				     skills:"",
        				     language:""
        				 }
        		}
        		var data=JSON.stringify(d);
        		console.log(data);
        		var i=get_cookie("currentPage");
        		var string=null;
					$.ajax({
						url:"./api/DrmsOnboarding/addOnboardings",
						type : "POST",
						data:data,
						contentType : "application/json",
						async : true,
						success:function() {
							if(i!=1){
								console.log(get_cookie("currentPage"));
								findPage();
							}else{
								var page1={
										pageNo:"",
										pageRecordSize:"",
										list:null,
										totalPageNo:"",
										parameter:string
									}
								var data=JSON.stringify(page1);
								loadPage(data);
							}
						}
					})
				}
function findDataList(){
	$.ajax({
		url:"./api/DrmsOnboarding/findDataList",
		type : "POST",
		async : true,
		success:function(data) {
			var dsgName=data.DsgName;
			var capName=data.CapName;
			var candShowId=data.CandShowId;
			var demandShowId=data.DemandShowId;
			var accountName=data.AccountName;
			$('#add_account').empty();
			$('#add_account').append('<option></option>');
			for(var a=0;a<accountName.length;a++){
				$('#add_account').append(
						'<option>'+accountName[a]+'</option>');
			}
			$('#add_capability').empty();
			$('#add_capability').append('<option></option>');
            for(var a=0;a<capName.length;a++){
	            $('#add_capability').append(
	            		'<option>'+capName[a]+'</option>');	
			}
            $('#add_designation').empty();
            $('#add_designation').append('<option></option>');
			for(var a=0;a<dsgName.length;a++){
				$('#add_designation').append(
						'<option>'+dsgName[a]+'</option>');
			}
		}
})}
function get_cookie(Name) {
	   var search = Name + "="
	   var returnvalue = "";
	   if (document.cookie.length > 0) {
	     sd = document.cookie.indexOf(search);
	     if (sd!= -1) {
	        sd += search.length;
	        end = document.cookie.indexOf(";", sd);
	        if (end == -1)
	         end = document.cookie.length;
	        returnvalue=unescape(document.cookie.substring(sd, end))
	      }
	   } 
	   return returnvalue;
	}

function add0(m){return m<10?'0'+m:m }
function format(Time)
{
	console.log(Time);
var time = new Date(Time+28800000);
var a=time.toUTCString();
console.log(a);
var A=a.split(' ');
var M=A[2];
console.log(M);
var y = time.getFullYear();
var m = time.getMonth()+1;
var d = time.getDate();
return M+'-'+add0(d)+', '+y;
}
function copyConfirm(){
	var account=$('#edit_account').val();
	var capability=$('#edit_capability').val();
	var demandRequest=$('#edit_demand_request').val();
	var candidate=$('#edit_candidate').val();
	var designation=$('#edit_designation').val();
	
	
	if(account!=''&&capability!=''&&demandRequest!=''&&candidate!=''&&designation!=''){
		for(var i=0;i<editDrmsRequestID.length;i++){
			console.log(editDrmsRequestID[i]);
			if(editDrmsRequestID.indexOf(demandRequest)<0){
				$('#edit_demand_request').addClass("alertEmpt");
				return;
			}else{
				$('#edit_demand_request').removeClass("alertEmpt");
			}
		}
		for(var i=0;i<editDrmsCandID.length;i++){
			if(editDrmsCandID.indexOf(candidate)<0){
				$('#edit_candidate').addClass("alertEmpt");
				return;
			}else{
				$('#edit_candidate').removeClass("alertEmpt");
			}
		}
	 $.MsgBox.Confirm("Tip:", "Are You Sure To copy The Data?",copyOnboarding);
	}else{
		if(account==''){
			$('#edit_account').addClass("alertEmpt");
		}
		if(capability==''){
			$('#edit_capability').addClass("alertEmpt");
		}
		if(demandRequest==''){
			$('#edit_demand_request').addClass("alertEmpt");
		}
		if(candidate==''){
			$('#edit_candidate').addClass("alertEmpt");
		}
		if(designation==''){
			$('#edit_designation').addClass("alertEmpt");
		}
		
	}
}
function deleteConfirm(){
	$.MsgBox.Confirm("Tip:", "Are You Sure To Delete The Data ", deleteOnboardings);
}
function updateConfirm(){
	var account=$('#edit_account').val();
	var capability=$('#edit_capability').val();
	var demandRequest=$('#edit_demand_request').val();
	var candidate=$('#edit_candidate').val();
	var designation=$('#edit_designation').val();
	if(account!=''&&capability!=''&&demandRequest!=''&&candidate!=''&&designation!=''){
		for(var i=0;i<editDrmsRequestID.length;i++){
			if(editDrmsRequestID.indexOf(demandRequest)<0){
				$('#edit_demand_request').addClass("alertEmpt");
				return;
			}else{
				$('#edit_demand_request').removeClass("alertEmpt");
			}
		}
		for(var i=0;i<editDrmsCandID.length;i++){
			if(editDrmsCandID.indexOf(candidate)<0){
				$('#edit_candidate').addClass("alertEmpt");
				return;
			}else{
				$('#edit_candidate').removeClass("alertEmpt");
			}
		}
	 $.MsgBox.Confirm("Tip:", "Are You Sure To Update The Data?",updateOnboardings);
	}else{
		if(account==''){
			$('#edit_account').addClass("alertEmpt");
		}
		if(capability==''){
			$('#edit_capability').addClass("alertEmpt");
		}
		if(demandRequest==''){
			$('#edit_demand_request').addClass("alertEmpt");
		}
		if(candidate==''){
			$('#edit_candidate').addClass("alertEmpt");
		}
		if(designation==''){
			$('#edit_designation').addClass("alertEmpt");
		}
		
	}
}
function addConfirm(){
	var account=$('#add_account').val();
	var capability=$('#add_capability').val();
	var demandRequest=$('#add_demand_request').val();
	var candidate=$('#add_candidate').val();
	var designation=$('#add_designation').val();
    if(account!=''&&capability!=''&&demandRequest!=''&&candidate!=''&&designation!=''){
    	console.log(addDrmsRequestID);
    	for(var i=0;i<addDrmsRequestID.length;i++){
    		console.log(demandRequest);
			if(addDrmsRequestID.indexOf(demandRequest)<0){
				$('#add_demand_request').addClass("alertEmpt");
				return;
			}else{
				$('#add_demand_request').removeClass("alertEmpt");
			}
		}
    	console.log(addDrmsCandID);
    	for(var i=0;i<addDrmsCandID.length;i++){
    		console.log(candidate);
			if(addDrmsCandID.indexOf(candidate)<0){
				$('#add_candidate').addClass("alertEmpt");
				return;
			}else{
				$('#add_candidate').removeClass("alertEmpt");
			}
		}
		$.MsgBox.Confirm("Tip:", "Are You Sure To Add The Data",addOnboardings);
	}else{
		if(account==''){
			$('#add_account').addClass("alertEmpt");
		}
		if(capability==''){
			$('#add_capability').addClass("alertEmpt");
		}
		if(demandRequest==''){
			$('#add_demand_request').addClass("alertEmpt");
		}
		if(candidate==''){
			$('#add_candidate').addClass("alertEmpt");
		}
		if(designation==''){
			$('#add_designation').addClass("alertEmpt");
		}
	}
}
function boxStyleChange(){
    $.MsgBox = {
        Confirm: function (title, msg, callback) {
            GenerateHtml("confirm", title, msg);
            btnOk(callback);
            btnNo();
        }
    }
    var GenerateHtml = function (type, title, msg) {
        var _html = "";
        _html += '<div id="mb_box"></div><div id="mb_con"><span id="mb_tit">' + title + '</span>';
        _html += '<a id="mb_ico">x</a><div id="mb_msg">' + msg + '</div><div id="mb_btnbox">';
        if (type == "alert") {
            _html += '<input id="mb_btn_ok" type="button" value="Sure" />';
        }
        if (type == "confirm") {
            _html += '<input id="mb_btn_ok" type="button" value="Sure" />';
            _html += '<input id="mb_btn_no" type="button" value="Cancel" />';
        }
        _html += '</div></div>';
        $("body").append(_html); 
         GenerateCss();
    }
    var GenerateCss = function () {
        $("#mb_box").css({ width: '100%', height: '100%', zIndex: '99999', position: 'fixed',
            filter: 'Alpha(opacity=60)', backgroundColor: 'black', top: '0', left: '0', opacity: '0.6'
        });
        $("#mb_con").css({ zIndex: '999999', width: '400px', position: 'fixed',
            backgroundColor: 'White', borderRadius: '15px'
        });
        $("#mb_tit").css({ display: 'block', fontSize: '14px', color: '#444', padding: '10px 15px',
            backgroundColor: '#DDD', borderRadius: '15px 15px 0 0',
            borderBottom: '3px solid #009BFE', fontWeight: 'bold'
        });
        $("#mb_msg").css({ padding: '20px', lineHeight: '20px',
            borderBottom: '1px dashed #DDD', fontSize: '13px'
        });
        $("#mb_ico").css({ display: 'block', position: 'absolute', right: '10px', top: '9px',
            border: '1px solid Gray', width: '18px', height: '18px', textAlign: 'center',
            lineHeight: '16px', cursor: 'pointer', borderRadius: '12px', fontFamily: '微软雅黑'
        });
        $("#mb_btnbox").css({ margin: '15px 0 10px 0', textAlign: 'center' });
        $("#mb_btn_ok,#mb_btn_no").css({ width: '85px', height: '30px', color: 'white', border: 'none',borderRadius:'5px'});
        $("#mb_btn_ok").css({ backgroundColor: '#369bf3'});
        $("#mb_btn_no").css({ backgroundColor: 'gray', marginLeft: '20px'});
        $("#mb_ico").hover(function () {
            $(this).css({ backgroundColor: 'Red', color: 'White' });
        }, function () {
            $(this).css({ backgroundColor: '#DDD', color: 'black' });
        });
        var _widht = document.documentElement.clientWidth;  
        var _height = document.documentElement.clientHeight; 
        var boxWidth = $("#mb_con").width();
        var boxHeight = $("#mb_con").height();
        $("#mb_con").css({ top: (_height - boxHeight) / 2 + "px", left: (_widht - boxWidth) / 2 + "px" });
    }
    var btnOk = function (callback) {
        $("#mb_btn_ok").click(function () {
            $("#mb_box,#mb_con").remove();
            if (typeof (callback) == 'function') {
                callback();
            }
        });
    }
    var btnNo = function () {
        $("#mb_btn_no,#mb_ico").click(function () {
            $("#mb_box,#mb_con").remove();
        });
    }
}

	function loadPage(data){
		var string = null;
		var currentPage;
		var id;
		var baseUrl="./api/DrmsOnboarding/findDrmsOnboarding";
		$.ajax({
			url:baseUrl,
			type : "POST",
			data:data,
			contentType : "application/json",
			async : true,
			success : function(data) {
				console.log(data);
				$('.tdb').empty();
				$('.tdb').append(
						'<tr style="color:#FFF;background-color:#A8B8C2;font-size: 13px; border:1px solid" id="thr">'+
						 '<th class="th" scope="col" width="9%" colspan="2" id="CGID">CG ID</th>'+
			             '<th class="th" scope="col" width="10%" colspan="2" id="AccountID">Account</th>'+
			             '<th class="th" scope="col" width="10%" colspan="2" id="CapabilityID">Capability</th>'+
			             '<th class="th" scope="col" width="15%" colspan="2" id="DemandRequestID">DemandRequest</th>'+
			             '<th class="th" scope="col" width="8%" colspan="2" id="CandidateID">Candidate</th>'+
		            	 '<th class="th" scope="col" width="8%" colspan="2" id="EnglishName">EnglishName</th>'+
		            	 '<th class="th" scope="col" width="9%" colspan="2" id="ChineseName">ChineseName</th>'+
			             '<th class="th" scope="col" width="8%" colspan="2" id="JoinDate">JoinDate</th>'+
				         '<th class="th" scope="col" width="8%" colspan="2" id="Status">Status</th>'+
			             '<th class="th" scope="col" width="10%" colspan="2" id="Language">Language</th>'+
			             '<th class="th" scope="col" width="5%" colspan="2" id="Option">Option</th>'+
			             '</tr>');
	if(data!=null ||data!=0){	
		console.log(data);
		OnBoarding=data.list;
		console.log(data.list);
		console.log(OnBoarding);
		console.log(OnBoarding.length);
		for(var i=0;i<OnBoarding.length;i++){
			var accountName="";
			if(OnBoarding[i].drmsAccount!=null){
			accountName=OnBoarding[i].drmsAccount.accountName;
			}
			var capName="";
			if(OnBoarding[i].drmsCapability!=null){
			capName=OnBoarding[i].drmsCapability.capName;
			}
			var demandShowId="";
			if(OnBoarding[i].drmsDemandRequest!=null){
			demandShowId=OnBoarding[i].drmsDemandRequest.demandShowId;
			}
			var candShowId="";
			if(OnBoarding[i].drmsCandidate!=null){
			candShowId=OnBoarding[i].drmsCandidate.candShowId;
			}
			var cgId="";
			if(OnBoarding[i].cgId!=null){
				cgId=OnBoarding[i].cgId;
			}
			var englishName="";
			if(OnBoarding[i].englishName!=null){
				englishName=OnBoarding[i].englishName;
			}
			var chineseName="";
			if(OnBoarding[i].chineseName!=null){
				chineseName=OnBoarding[i].chineseName;
			}
			var joinDate="";
			if(format(OnBoarding[i].joinDate)!=format("1970-01-01")){
				joinDate=format(OnBoarding[i].joinDate);
			}
			var status="";
			if(OnBoarding[i].status!=null){
				status=OnBoarding[i].status;
			}
			var language="";
			if(OnBoarding[i].language!=null){
				language=OnBoarding[i].language;
			}
				$('.tdb').append(
						 '<tr align="center" style="background-color:white;border:1px solid #ddd">'+
						 '<td class="th" scope="col" width="9%" colspan="2">'+cgId+ '</td>'+
						 '<td class="th" scope="col" width="10%" colspan="2">'+accountName+ '</td>'+
						 '<td class="th" scope="col" width="10%" colspan="2">'+capName+ '</td>'+
						 '<td class="th" scope="col" width="15%" colspan="2">'+demandShowId+ '</td>'+
						 '<td class="th" scope="col" width="8%" colspan="2">'+candShowId+ '</td>'+
						 '<td class="th" scope="col" width="8%" colspan="2">'+englishName+ '</td>'+
						 '<td class="th" scope="col" width="9%" colspan="2">'+chineseName+ '</td>'+
						 '<td class="th" scope="col" width="8%" colspan="2">'+joinDate+ '</td>'+
						 '<td class="th" scope="col" width="8%" colspan="2">'+status+ '</td>'+
						 '<td class="th" scope="col" width="10%" colspan="2">'+language+ '</td>'+
						 '<td class="th" scope="col" width="5%" colspan="2"><span  id="'+i+'" class="tb-edit"></span></td>'+
						 '</tr>');
				        }   
					currentPage=data.pageNo;
					document.cookie="currentPage="+currentPage;
					$('.totalPageNo').html(data.totalPageNo);
					$('.currentPageNo').html(currentPage)
					$('.pageNumber').empty();
					var totalPage=data.totalPageNo;
					if(totalPage<=5){
						for(var i=1;i<=totalPage;i++){
							if(i==currentPage){
								$('.pageNumber').append("<input type='button' class='paging click' style='background-color:#fff;border:1px solid #ddd;padding-top:5px;padding-right:10px;padding-bottom:5px;padding-left:10px;text-align:center;' value='"+i+"'>");
							}else{
								$('.pageNumber').append("<input type='button' class='paging' style='background-color:#fff;border:1px solid #ddd;padding-top:5px;padding-right:10px;padding-bottom:5px;padding-left:10px;text-align:center;' value='"+i+"'>");
							}
						}
					}else{
						if(currentPage<=3){
							for(var i=1;i<=5;i++){
								if(i==currentPage){
									$('.pageNumber').append("<input type='button' class='paging click' style='background-color:#fff;border:1px solid #ddd;padding-top:5px;padding-right:10px;padding-bottom:5px;padding-left:10px;text-align:center;' value='"+i+"'>");
								}else{
									$('.pageNumber').append("<input type='button' class='paging' style='background-color:#fff;border:1px solid #ddd;padding-top:5px;padding-right:10px;padding-bottom:5px;padding-left:10px;text-align:center;' value='"+i+"'>");
								}
							}
						}else{
							if(currentPage>totalPage-4){
								for(var i=totalPage-4;i<=totalPage;i++){
									if(i==currentPage){
										$('.pageNumber').append("<input type='button' class='paging click' style='background-color:#fff;border:1px solid #ddd;padding-top:5px;padding-right:10px;padding-bottom:5px;padding-left:10px;text-align:center;' value='"+i+"'>");
									}else{
										$('.pageNumber').append("<input type='button' class='paging' style='background-color:#fff;border:1px solid #ddd;padding-top:5px;padding-right:10px;padding-bottom:5px;padding-left:10px;text-align:center;' value='"+i+"'>");
									}
								}
							}else{
								for(var i=currentPage-2;i<currentPage+3;i++){
									if(i==currentPage){
										$('.pageNumber').append("<input type='button' class='paging click' style='background-color:#fff;border:1px solid #ddd;padding-top:5px;padding-right:10px;padding-bottom:5px;padding-left:10px;text-align:center;' value='"+i+"'>");
									}else{
										$('.pageNumber').append("<input type='button' class='paging' style='background-color:#fff;border:1px solid #ddd;padding-top:5px;padding-right:10px;padding-bottom:5px;padding-left:10px;text-align:center;' value='"+i+"'>");
									}
								}
							}
						}
					}
				}
			}
		})
	}
	function findPage(){
		var string = document.getElementById("name").value;
		console.log(string);
		var o=get_cookie("currentPage");
		console.log(o);
		var page2={
				pageNo:o,
				pageRecordSize:"",
				list:null,
				totalPageNo:"",
				parameter:string
			}
		var data=JSON.stringify(page2);
		console.log(data);
		loadPage(data);
	}
	function copyOnboarding(){
		var id=get_cookie("id");
		var cgid=$('#edit_cg_id').val();
		var account=$('#edit_account').val();
		var capability=$('#edit_capability').val();
		var demandRequest=$('#edit_demand_request').val();
		var candidate=$('#edit_candidate').val();
		var englishName=$('#edit_english_name').val();
		var chineseName=$('#edit_chinese_name').val();
		var status=$('#edit_status').val();
		var project=$('#edit_project').val();
		var roleName=$('#edit_role_name').val();
		var language=$('#edit_language').val();
		var a=$('#edit_join_date').val();
		if(a==''){
			var b=new Date();
			var joinDate=b.getFullYear()+"-"+add0(b.getMonth()+1)+"-"+add0(b.getDate());
		}else{
			var b= new Date(a);
			var joinDate=b.getFullYear()+"-"+add0(b.getMonth()+1)+"-"+add0(b.getDate());
		}
		console.log(joinDate);
		var capabilitySupervisor=$('#edit_capability_supervisor').val();
		var projectLeader=$('#edit_project_leader').val();
		var billableStatus=$('#edit_billable_status').val();
		var designation=$('#edit_designation').val();
		console.log(id);
		var d={
				 id:id,
				 cgId:cgid,
				 englishName:englishName,
				 chineseName:chineseName,
				 joinDate:joinDate,
				 project:project,
				 projectLeader:projectLeader,
				 billableStatus:billableStatus,
				 language:language,
				 status:status,
				 roleName:roleName,
				 capabilitySupervisor:capabilitySupervisor,
				 drmsDesigation:{
				 	 dsgId:"",
				     dsgName:designation
				 },
				 drmsCapability:{
				 	 capId:"",
				     capName:capability,
				     capManager:"",
				     capShortName:""
				 },
				drmsAccount:{
				     accountId:"",
			         accountName:account,
			         shortName:"",
			         accountPartner:""
				 },
				drmsDemandRequest:{
				     id:"",
				     raiseDate:"",
				     isflp:"",
				     hiringReason:"",
				     refName:"",
				     language:"",
				     primarySkill:"",
				     secondarySkill:"",
				     targetJoinDate:"",
				     status:"",
				     demandShowId:demandRequest
				 },
				 drmsCandidate:{
				     candId:"",
				     candShowId:candidate,
				     candName:"",
				     recruiter:"",
				     resource:"",
				     resume:"",
				     contactDate:"",
				     currentLocation:"",
				     telphone:"",
				     email:"",
				     year:"",
				     currentCompany:"",
				     currentSalary:"",
				     dep:"",
				     position:"",
				     status:"",
				     comments:"",
				     domain:"",
				     skills:"",
				     language:""
				 }
		}
		console.log(d);
		var data=JSON.stringify(d);
		var i=get_cookie("currentPage");
		var string=null;
		$.ajax({
			url:"./api/DrmsOnboarding/addOnboardings",
			type : "POST",
			data:data,
			contentType : "application/json",
			async : true,
			success:function() {
				if(i!=1){
					console.log(get_cookie("currentPage"));
					findPage();
				}else{
					var page1={
							pageNo:"",
							pageRecordSize:"",
							list:null,
							totalPageNo:"",
							parameter:string
						}
					var data=JSON.stringify(page1);
					loadPage(data);
				}
			}
		})
	}
	